import Vue from 'vue'
import Router from 'vue-router'
import page from './page'
import store from '../store/store.js'

Vue.use(Router)

const router = new Router({routes:page})

// 每个页面都强制验证是否授权登录
router.beforeEach((to, from, next) => {
  // console.log(to.path)
  // console.log(store.state.token)
  // if(to.path != '/authorize'){
  //   console.log('---')
  //   console.log(store.state.code)
  //   console.log('---')
  // }
  // console.log(window.location.href.split('#')[1].length>1)
  // let linkPath = window.location.href.split('#')[1]
  // if(linkPath.length>1){
  //   next(linkPath)
  //   console.log(2)
  //   return
  // }else{
  //   if (to.path === '/authorize' && store.state.token) {
  //     next('/index')
  //     return
  //   }
  //   if (to.path != '/authorize' && !store.state.token) {
  //     next('/authorize')
  //     return
  //   }
  // }

  if (to.path === '/authorize' && store.state.token) {
    next('/index')
    return
  }
  if (to.path != '/authorize' && !store.state.token) {
    next('/authorize')
    return
  }
  // if (to.path === '/binding/bind' && store.state.bind==1) {
  //   next('/userCenter')
  //   return
  // }
  // if (to.path != '/authorize' && store.state.token) {
  //   console.log('youle--')
  //   next('/index')
  //   return
  // }

  next()

})
export default router
